<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.ico">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha256-wiz7ZSCn/btzhjKDQBms9Hx4sSeUYsDrTLg7roPstac=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.css" integrity="sha256-6cQIC71/iBIYXFK+0RHAvwmjwWzkWd+r7v/BX3/vZDc=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/green/pace-theme-minimal.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous"></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"sumumm.github.io","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.19.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":true,"height":300},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="本文主要是Hexo中的两种的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:type" content="article">
<meta property="og:title" content="LV01-Hexo-03-Hexo的两种插件">
<meta property="og:url" content="https://sumumm.github.io/post/72cb261c.html">
<meta property="og:site_name" content="苏木">
<meta property="og:description" content="本文主要是Hexo中的两种的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2023-07-02T08:16:53.000Z">
<meta property="article:modified_time" content="2025-06-13T16:25:57.072Z">
<meta property="article:author" content="苏木">
<meta property="article:tag" content="博客搭建">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://sumumm.github.io/post/72cb261c.html">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://sumumm.github.io/post/72cb261c.html","path":"post/72cb261c.html","title":"LV01-Hexo-03-Hexo的两种插件"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>LV01-Hexo-03-Hexo的两种插件 | 苏木</title>
  








    <script src="/js/browser_tools_disable.js"></script>

  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<!-- hexo injector head_end start --><link rel="stylesheet" href="https://unpkg.com/hexo-next-tags-plus@latest/lib/tag_plus.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">苏木</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">我的学习之路</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>苏木的家</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类页<span class="badge">42</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档页<span class="badge">673</span></a></li><li class="menu-item menu-item-flink"><a href="/flink/" rel="section"><i class="fa fa-link fa-fw"></i>友人帐</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于我</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80%E3%80%81Hexo%E7%9A%84%E6%8F%92%E4%BB%B6"><span class="nav-text">一、Hexo的插件</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E4%B8%A4%E7%A7%8D%E6%8F%92%E4%BB%B6"><span class="nav-text">1. 两种插件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E6%8F%92%E4%BB%B6%E7%9A%84%E5%8A%A0%E8%BD%BD%E6%B5%81%E7%A8%8B"><span class="nav-text">2. 插件的加载流程</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-%E8%84%9A%E6%9C%AC%EF%BC%88Scripts%EF%BC%89%E7%9A%84%E5%8A%A0%E8%BD%BD"><span class="nav-text">2.1 脚本（Scripts）的加载</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-%E6%8F%92%E4%BB%B6%EF%BC%88Packages%EF%BC%89%E7%9A%84%E5%8A%A0%E8%BD%BD"><span class="nav-text">2.2 插件（Packages）的加载</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-Hexo%E7%9B%B8%E5%85%B3%E5%87%BD%E6%95%B0"><span class="nav-text">3. Hexo相关函数</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-%E8%BF%87%E6%BB%A4%E5%99%A8%EF%BC%88Filter%EF%BC%89"><span class="nav-text">3.1 过滤器（Filter）</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#3-1-1-%E5%87%BD%E6%95%B0%E5%8E%9F%E5%9E%8B"><span class="nav-text">3.1.1 函数原型</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-1-2-%E5%87%BD%E6%95%B0%E4%BD%BF%E7%94%A8%E5%8F%8A%E8%AF%B4%E6%98%8E"><span class="nav-text">3.1.2 函数使用及说明</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-%E6%B3%A8%E5%85%A5%E5%99%A8%EF%BC%88Injector%EF%BC%89"><span class="nav-text">3.2 注入器（Injector）</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#3-2-1-%E5%87%BD%E6%95%B0%E5%8E%9F%E5%9E%8B"><span class="nav-text">3.2.1 函数原型</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-2-2-%E7%A4%BA%E4%BE%8B%E7%A8%8B%E5%BA%8F"><span class="nav-text">3.2.2 示例程序</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-3-%E8%BE%85%E5%8A%A9%E5%87%BD%E6%95%B0%EF%BC%88Helper%EF%BC%89"><span class="nav-text">3.3 辅助函数（Helper）</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#3-3-1-%E5%87%BD%E6%95%B0%E5%8E%9F%E5%9E%8B"><span class="nav-text">3.3.1 函数原型</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-3-2-%E5%87%BD%E6%95%B0%E4%BD%BF%E7%94%A8%E5%8F%8A%E8%AF%B4%E6%98%8E"><span class="nav-text">3.3.2 函数使用及说明</span></a></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%8C%E3%80%81%E5%B0%9D%E8%AF%95Hexo%E4%B8%AD%E6%9C%80%E5%9F%BA%E6%9C%AC%E7%9A%84%E6%8F%92%E4%BB%B6"><span class="nav-text">二、尝试Hexo中最基本的插件</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E8%84%9A%E6%9C%AC%EF%BC%88Scripts%EF%BC%89%E6%B5%8B%E8%AF%95"><span class="nav-text">1. 脚本（Scripts）测试</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-1-%E8%BF%87%E6%BB%A4%E5%99%A8%EF%BC%88Filter%EF%BC%89%E6%B5%8B%E8%AF%95"><span class="nav-text">1.1 过滤器（Filter）测试</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-2-%E6%B3%A8%E5%85%A5%E5%99%A8%EF%BC%88Injector%EF%BC%89%E6%B5%8B%E8%AF%95"><span class="nav-text">1.2 注入器（Injector）测试</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E6%8F%92%E4%BB%B6%EF%BC%88Packages%EF%BC%89%E6%B5%8B%E8%AF%95"><span class="nav-text">2. 插件（Packages）测试</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-%E5%88%9B%E5%BB%BA%E6%8F%92%E4%BB%B6%E6%96%87%E4%BB%B6%E5%A4%B9%E5%B9%B6%E8%BF%9B%E8%A1%8C%E5%88%9D%E5%A7%8B%E5%8C%96"><span class="nav-text">2.1 创建插件文件夹并进行初始化</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-%E5%88%9B%E5%BB%BAindex-js%E4%B8%BB%E7%A8%8B%E5%BA%8F%E6%96%87%E4%BB%B6%E5%B9%B6%E6%B7%BB%E5%8A%A0%E6%B5%8B%E8%AF%95%E7%A8%8B%E5%BA%8F"><span class="nav-text">2.2 创建index.js主程序文件并添加测试程序</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-3-%E6%89%93%E5%8C%85%E5%B9%B6%E5%8F%91%E5%B8%83%E7%A8%8B%E5%BA%8F%E5%88%B0npm"><span class="nav-text">2.3 打包并发布程序到npm</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-4-%E8%BF%9B%E5%85%A5%E6%B5%8B%E8%AF%95%E7%AB%99%E7%82%B9%E5%B9%B6%E5%AE%89%E8%A3%85%E6%8F%92%E4%BB%B6"><span class="nav-text">2.4 进入测试站点并安装插件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-5-%E5%90%AF%E5%8A%A8%E6%9C%AC%E5%9C%B0%E9%A2%84%E8%A7%88"><span class="nav-text">2.5 启动本地预览</span></a></li></ol></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="苏木"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">苏木</p>
  <div class="site-description" itemprop="description">莫道桑榆晚，为霞尚满天</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">673</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">42</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">43</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/sumumm" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;sumumm" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://sumumm.github.io/post/72cb261c.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="苏木">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏木">
      <meta itemprop="description" content="莫道桑榆晚，为霞尚满天">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="LV01-Hexo-03-Hexo的两种插件 | 苏木">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          LV01-Hexo-03-Hexo的两种插件
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-07-02 16:16:53" itemprop="dateCreated datePublished" datetime="2023-07-02T16:16:53+08:00">2023-07-02</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/" itemprop="url" rel="index"><span itemprop="name">博客搭建</span></a>
        </span>
    </span>

  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>3.9k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>14 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>本文主要是Hexo中的两种的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。</p>
<span id="more"></span>

<!-- Photo: https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/03%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/LV01-Hexo-03-Hexo%E7%9A%84%E4%B8%A4%E7%A7%8D%E6%8F%92%E4%BB%B6/img/ -->

<details class="folding-tag" blue><summary> 点击查看使用工具及版本 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center" width=150px>Windows</td>        <td align="left">windows11</td>    </tr>    <tr>        <td align="center">Ubuntu</td>        <td align="left">Ubuntu16.04的64位版本</td>      </tr>    <tr>        <td align="center">VMware® Workstation 16 Pro</td>        <td align="left">16.2.3 build-19376536</td>      </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看本文参考资料 </summary>
              <div class='content'>
              <table>    <tr><td align="center">参考方向  </td><td align="center">参考原文</td></tr>    <tr><td align="left">---</td><td align="left"><a href="" target="_blank">--- <i class="fa fa-external-link-alt"></i> </a></td></tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看相关文件下载 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center">---</td>        <td align="left">--- <a href="" target="_blank">  <i class="fa fa-external-link-alt"></i></a></td>      </tr></table>
              </div>
            </details>

<p>在看<code>Hexo</code>文档的时候发现了关于<code>Hexo</code>中的插件的相关知识，于是就去找了一些插件的源码，了解了一下大概的插件编写的格式，本文是记录一下自己开始尝试<code>Hexo</code>插件的第一步。</p>
<h1 id="一、Hexo的插件"><a href="#一、Hexo的插件" class="headerlink" title="一、Hexo的插件"></a><font size=3>一、<code>Hexo</code>的插件</font></h1><h2 id="1-两种插件"><a href="#1-两种插件" class="headerlink" title="1. 两种插件"></a><font size=3>1. 两种插件</font></h2><p>在<code>Hexo</code>中，有强大的插件系统，使开发者能偶轻松扩展功能而不用修改核心模块的源码。它的插件分为两种：脚本（<code>Scripts</code>）和插件（<code>Packages</code>）。</p>
<p>如果自己的代码很简单，可以编写脚本，这个时候只需要把自己编写的<code>JavaScript</code>文件放到<code>[blogRoot]/scripts</code>文件夹，整个文件夹一般默认是没有的，所以需要自己在站点根目录下创建，整个文件夹中的脚本文件在启动时就会自动载入。</p>
<p>另一种则适合自己的代码较为复杂的情况，或是自己想要发布到<code>npm</code>上，首先，在<code>node_modules</code>文件夹中建立文件夹，文件夹名称开头必须为<code>hexo-</code>，如此一来<code>Hexo</code>才会在启动时载入，否则<code>Hexo</code>将会忽略它。文件夹内至少要包含<code>2</code>个文件：一个是主程序，另一个是 <code>package.json</code>，描述插件的用途和所依赖的插件。</p>
<details class="note info no-icon"><summary><p>点击查看相关文档</p>
</summary>
<table>
    <tr>
        <td align="left">
        Hexo说明文档
        </td>
        <td align="left">
        <a href="https://hexo.io/zh-cn/docs/" target="_blank">https://hexo.io/zh-cn/docs/</a>
        </td>
    </tr>
    <tr>
        <td align="left">
        Hexo API文档
        </td>
        <td align="left">
        <a href="https://hexo.io/zh-cn/api/" target="_blank">https://hexo.io/zh-cn/api/</a>
        </td>
    </tr>
</table>

</details>

<h2 id="2-插件的加载流程"><a href="#2-插件的加载流程" class="headerlink" title="2. 插件的加载流程"></a><font size=3>2. 插件的加载流程</font></h2><p>这里列出的相关内容，是在自己还未掌握<code>JavaScript</code>的情况下，后边对<code>JavaScript</code>有了更深入的了解后，会将此部分错误或者不合适的地方进行更新。</p>
<h3 id="2-1-脚本（Scripts）的加载"><a href="#2-1-脚本（Scripts）的加载" class="headerlink" title="2.1 脚本（Scripts）的加载"></a><font size=3>2.1 脚本（<code>Scripts</code>）的加载</font></h3><p>在阅读源码的过程中，有这么一部分代码，大致理解一下，就是使用此函数完成了根目录下<code>scripts</code>文件夹和主题文件目录下的<code>scripts</code>文件夹中的各个脚本文件的加载。</p>
<figure class="highlight javascript"><figcaption><span>JavaScript [blogRoot]/node_modules/hexo/lib/hexo/load_plugins.js</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">loadScripts</span>(<span class="params">ctx</span>) &#123;</span><br><span class="line">  <span class="keyword">const</span> baseDirLength = ctx.<span class="property">base_dir</span>.<span class="property">length</span>;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">function</span> <span class="title function_">displayPath</span>(<span class="params">path</span>) &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="title function_">magenta</span>(path.<span class="title function_">substring</span>(baseDirLength));</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">return</span> <span class="title class_">Promise</span>.<span class="title function_">filter</span>([</span><br><span class="line">    ctx.<span class="property">theme_script_dir</span>,</span><br><span class="line">    ctx.<span class="property">script_dir</span></span><br><span class="line">  ], <span class="function"><span class="params">scriptDir</span> =&gt;</span> &#123; <span class="comment">// Ignore the directory if it does not exist</span></span><br><span class="line">    <span class="keyword">return</span> scriptDir ? <span class="title function_">exists</span>(scriptDir) : <span class="literal">false</span>;</span><br><span class="line">  &#125;).<span class="title function_">map</span>(<span class="function"><span class="params">scriptDir</span> =&gt;</span> <span class="title function_">listDir</span>(scriptDir).<span class="title function_">map</span>(<span class="function"><span class="params">name</span> =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">const</span> path = <span class="title function_">join</span>(scriptDir, name);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> ctx.<span class="title function_">loadPlugin</span>(path).<span class="title function_">then</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">      ctx.<span class="property">log</span>.<span class="title function_">debug</span>(<span class="string">&#x27;Script loaded: %s&#x27;</span>, <span class="title function_">displayPath</span>(path));</span><br><span class="line">    &#125;).<span class="title function_">catch</span>(<span class="function"><span class="params">err</span> =&gt;</span> &#123;</span><br><span class="line">      ctx.<span class="property">log</span>.<span class="title function_">error</span>(&#123;err&#125;, <span class="string">&#x27;Script load failed: %s&#x27;</span>, <span class="title function_">displayPath</span>(path));</span><br><span class="line">    &#125;);</span><br><span class="line">  &#125;));</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="2-2-插件（Packages）的加载"><a href="#2-2-插件（Packages）的加载" class="headerlink" title="2.2 插件（Packages）的加载"></a><font size=3>2.2 插件（<code>Packages</code>）的加载</font></h3><p><code>plugins</code>的加载是通过以下函数完成的。</p>
<figure class="highlight javascript"><figcaption><span>JavaScript [blogRoot]/node_modules/hexo/lib/hexo/load_plugins.js</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">loadModules</span>(<span class="params">ctx</span>) &#123;</span><br><span class="line">  <span class="keyword">return</span> <span class="title function_">loadModuleList</span>(ctx).<span class="title function_">map</span>(<span class="function"><span class="params">name</span> =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">const</span> path = ctx.<span class="title function_">resolvePlugin</span>(name);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// Load plugins</span></span><br><span class="line">    <span class="keyword">return</span> ctx.<span class="title function_">loadPlugin</span>(path).<span class="title function_">then</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">      ctx.<span class="property">log</span>.<span class="title function_">debug</span>(<span class="string">&#x27;Plugin loaded: %s&#x27;</span>, <span class="title function_">magenta</span>(name));</span><br><span class="line">    &#125;).<span class="title function_">catch</span>(<span class="function"><span class="params">err</span> =&gt;</span> &#123;</span><br><span class="line">      ctx.<span class="property">log</span>.<span class="title function_">error</span>(&#123;err&#125;, <span class="string">&#x27;Plugin load failed: %s&#x27;</span>, <span class="title function_">magenta</span>(name));</span><br><span class="line">    &#125;);</span><br><span class="line">  &#125;);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="3-Hexo相关函数"><a href="#3-Hexo相关函数" class="headerlink" title="3. Hexo相关函数"></a><font size=3>3. <code>Hexo</code>相关函数</font></h2><p>在使用插件之前，肯定要先了解一下基本的函数啦，这一节的内容大部分来自于<code>Hexo</code>官方文档。</p>
<h3 id="3-1-过滤器（Filter）"><a href="#3-1-过滤器（Filter）" class="headerlink" title="3.1 过滤器（Filter）"></a><font size=3>3.1 过滤器（<code>Filter</code>）</font></h3><h4 id="3-1-1-函数原型"><a href="#3-1-1-函数原型" class="headerlink" title="3.1.1 函数原型"></a><font size=3>3.1.1 函数原型</font></h4><p>过滤器用于修改特定文件，<code>Hexo</code>将这些文件依序传给过滤器，而过滤器可以针对文件进行修改。</p>
<details class="note info no-icon"><summary><p>点击查看函数原型</p>
</summary>
<figure class="highlight javascript"><figcaption><span>JavaScript [blogRoot]/node_modules/hexo/lib/extend/filter.js</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">class</span> <span class="title class_">Filter</span> &#123;</span><br><span class="line">  <span class="title function_">constructor</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="variable language_">this</span>.<span class="property">store</span> = &#123;&#125;;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="title function_">register</span>(<span class="params">type, fn, priority</span>) &#123;</span><br><span class="line">    <span class="keyword">if</span> (!priority) &#123;</span><br><span class="line">      <span class="keyword">if</span> (<span class="keyword">typeof</span> type === <span class="string">&#x27;function&#x27;</span>) &#123;</span><br><span class="line">        priority = fn;</span><br><span class="line">        fn = type;</span><br><span class="line">        type = <span class="string">&#x27;after_post_render&#x27;</span>;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (<span class="keyword">typeof</span> fn !== <span class="string">&#x27;function&#x27;</span>) <span class="keyword">throw</span> <span class="keyword">new</span> <span class="title class_">TypeError</span>(<span class="string">&#x27;fn must be a function&#x27;</span>);</span><br><span class="line"></span><br><span class="line">    type = typeAlias[type] || type;</span><br><span class="line">    priority = priority == <span class="literal">null</span> ? <span class="number">10</span> : priority;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">const</span> store = <span class="variable language_">this</span>.<span class="property">store</span>[type] || [];</span><br><span class="line">    <span class="variable language_">this</span>.<span class="property">store</span>[type] = store;</span><br><span class="line"></span><br><span class="line">    fn.<span class="property">priority</span> = priority;</span><br><span class="line">    store.<span class="title function_">push</span>(fn);</span><br><span class="line"></span><br><span class="line">    store.<span class="title function_">sort</span>(<span class="function">(<span class="params">a, b</span>) =&gt;</span> a.<span class="property">priority</span> - b.<span class="property">priority</span>);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</details>

<h4 id="3-1-2-函数使用及说明"><a href="#3-1-2-函数使用及说明" class="headerlink" title="3.1.2 函数使用及说明"></a><font size=3>3.1.2 函数使用及说明</font></h4><figure class="highlight javascript"><figcaption><span>JavaScript</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">hexo.<span class="property">extend</span>.<span class="property">filter</span>.<span class="title function_">register</span>(type, <span class="keyword">function</span>(<span class="params"></span>) &#123;</span><br><span class="line">  <span class="comment">// User configuration</span></span><br><span class="line">  <span class="keyword">const</span> &#123; config &#125; = <span class="variable language_">this</span>;</span><br><span class="line">  <span class="keyword">if</span> (config.<span class="property">external_link</span>.<span class="property">enable</span>) <span class="comment">// do something...</span></span><br><span class="line"></span><br><span class="line">  <span class="comment">// Theme configuration</span></span><br><span class="line">  <span class="keyword">const</span> &#123; <span class="attr">config</span>: themeCfg &#125; = <span class="variable language_">this</span>.<span class="property">theme</span>;</span><br><span class="line">  <span class="keyword">if</span> (themeCfg.<span class="property">fancybox</span>) <span class="comment">// do something...</span></span><br><span class="line"></span><br><span class="line">&#125;, priority);</span><br></pre></td></tr></table></figure>

<p><strong>type</strong>：为过滤器列表，它应该是一个字符串数据，使用的时候要加上<code>&#39;&#39;</code>，可以是以下值:</p>
<table>
  <tr>
    <td align="center">
    type的值
    </td>
    <td align="center">
    说明
    </td>
  </tr>
  <tr>
    <td align="center">
    before_post_render
    </td>
    <td align="left">
    在文章开始渲染前执行。
    </td>
  </tr>
  <tr>
    <td align="center">
    after_post_render
    </td>
    <td align="left">
    在文章渲染完成后执行。
    </td>
  </tr>
  <tr>
    <td align="center">
    before_exit
    </td>
    <td align="left">
    在 Hexo 即将结束时执行，也就是在 hexo.exit 被调用后执行。
    </td>
  </tr>
  <tr>
    <td align="center">
    before_generate
    </td>
    <td align="left">
    在生成器解析前执行。
    </td>
  </tr>
  <tr>
    <td align="center">
    after_generate
    </td>
    <td align="left">
    在生成器解析后执行。
    </td>
  </tr>
  <tr>
    <td align="center">
    template_locals
    </td>
    <td align="left">
    修改模板的<a href="https://hexo.io/zh-cn/docs/variables" target="_blank">局部变量</a>。
    </td>
  </tr>
  <tr>
    <td align="center">
    after_init
    </td>
    <td align="left">
    在 Hexo 初始化完成后执行，也就是在 hexo.init 执行完成后执行。
    </td>
  </tr>
  <tr>
    <td align="center">
    new_post_path
    </td>
    <td align="left">
    用来决定新建文章的路径，在建立文章时执行。
    </td>
  </tr>
  <tr>
    <td align="center">
    post_permalink
    </td>
    <td align="left">
    用来决定文章的永久链接。
    </td>
  </tr>
  <tr>
    <td align="center">
    after_render
    </td>
    <td align="left">
    在<a href="https://hexo.io/zh-cn/api/rendering" target="_blank">渲染</a>后执行。
    </td>
  </tr>
  <tr>
    <td align="center">
    server_middleware
    </td>
    <td align="left">
    新增服务器的 Middleware。app 是一个<a href="https://github.com/senchalabs/connect" target="_blank">Connect</a>实例。
    </td>
  </tr>
</table>
**priority**：是过滤器的优先级，`priority` 值越低，过滤器会越早执行，默认的 `priority` 是 10。建议提供配置选项如 `hexo.config.your_plugin.priority`，让用户自行决定过滤器的优先级。

<h3 id="3-2-注入器（Injector）"><a href="#3-2-注入器（Injector）" class="headerlink" title="3.2 注入器（Injector）"></a><font size=3>3.2 注入器（<code>Injector</code>）</font></h3><h4 id="3-2-1-函数原型"><a href="#3-2-1-函数原型" class="headerlink" title="3.2.1 函数原型"></a><font size=3>3.2.1 函数原型</font></h4><p>注入器被用于将静态代码片段注入生成的<code>HTML </code>的<code>&lt;head&gt;&lt;/head&gt;</code>或<code>&lt;body&gt;&lt;/body&gt;</code>中。<code>Hexo</code>将在 <code>after_render:html</code>过滤器 <strong>之前</strong> 完成注入。</p>
<details class="note info no-icon"><summary><p>点击查看函数原型</p>
</summary>
<figure class="highlight javascript"><figcaption><span>JavaScript [blogRoot]/node_modules/hexo/lib/extend/injector.js</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">class</span> <span class="title class_">Injector</span> &#123;</span><br><span class="line">  <span class="title function_">constructor</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="variable language_">this</span>.<span class="property">store</span> = &#123;</span><br><span class="line">      <span class="attr">head_begin</span>: &#123;&#125;,</span><br><span class="line">      <span class="attr">head_end</span>: &#123;&#125;,</span><br><span class="line">      <span class="attr">body_begin</span>: &#123;&#125;,</span><br><span class="line">      <span class="attr">body_end</span>: &#123;&#125;</span><br><span class="line">    &#125;;</span><br><span class="line"></span><br><span class="line">  <span class="title function_">register</span>(<span class="params">entry, value, to = <span class="string">&#x27;default&#x27;</span></span>) &#123;</span><br><span class="line">    <span class="keyword">if</span> (!entry) <span class="keyword">throw</span> <span class="keyword">new</span> <span class="title class_">TypeError</span>(<span class="string">&#x27;entry is required&#x27;</span>);</span><br><span class="line">    <span class="keyword">if</span> (<span class="keyword">typeof</span> value === <span class="string">&#x27;function&#x27;</span>) value = <span class="title function_">value</span>();</span><br><span class="line"></span><br><span class="line">    <span class="keyword">const</span> entryMap = <span class="variable language_">this</span>.<span class="property">store</span>[entry] || <span class="variable language_">this</span>.<span class="property">store</span>.<span class="property">head_end</span>;</span><br><span class="line">    <span class="keyword">const</span> valueSet = entryMap[to] || <span class="keyword">new</span> <span class="title class_">Set</span>();</span><br><span class="line">    valueSet.<span class="title function_">add</span>(value);</span><br><span class="line">    entryMap[to] = valueSet;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</details>

<ul>
<li>函数使用及说明</li>
</ul>
<figure class="highlight javascript"><figcaption><span>JavaScript</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo.<span class="property">extend</span>.<span class="property">injector</span>.<span class="title function_">register</span>(entry, value, to)</span><br></pre></td></tr></table></figure>

<ul>
<li><strong>entry</strong>:字符串类型数据，表示代码片段注入的位置，接受以下值：</li>
</ul>
<p>（1）<code>head_begin</code>: 注入在 <code>&lt;head&gt;</code> 之后（默认）</p>
<p>（2）<code>head_end</code>: 注入在 <code>&lt;/head&gt;</code> 之前</p>
<p>（3）<code>body_begin</code>: 注入在 <code>&lt;body&gt;</code> 之后</p>
<p>（4）<code>body_end</code>: 注入在 <code>&lt;/body&gt;</code> 之前</p>
<ul>
<li><p><strong>value</strong>:字符串，或者支持返回值为字符串的函数，表示需要注入的代码片段。</p>
</li>
<li><p><strong>to</strong>:字符串类型数据，需要注入代码片段的页面类型，接受以下值：</p>
</li>
</ul>
<p>（1）<code>default</code>: 注入到每个页面（默认值）</p>
<p>（2）<code>home</code>: 只注入到主页（<code>is_home() </code>为 <code>true</code> 的页面）</p>
<p>（3）<code>post</code>: 只注入到文章页面（<code>is_post()</code> 为 <code>true</code> 的页面）</p>
<p>（4）<code>page</code>: 只注入到独立页面（<code>is_page()</code> 为 <code>true</code> 的页面）</p>
<p>（5）<code>archive</code>: 只注入到归档页面（<code>is_archive()</code> 为 <code>true</code> 的页面）</p>
<p>（6）<code>category</code>: 只注入到分类页面（<code>is_category()</code> 为 <code>true</code> 的页面）</p>
<p>（7）<code>tag</code>: 只注入到标签页面（<code>is_tag()</code> 为 <code>true</code> 的页面）</p>
<p>其他自定义 <code>layout</code> 名称，自定义 <code>layout</code> 参考<a href="https://hexo.io/zh-cn/docs/writing" target="_blank">写作 - 布局（<code>Layout</code>）</a>实例。 </p>
<h4 id="3-2-2-示例程序"><a href="#3-2-2-示例程序" class="headerlink" title="3.2.2 示例程序"></a><font size=3>3.2.2 示例程序</font></h4><figure class="highlight javascript"><figcaption><span>JavaScript</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> css = hexo.<span class="property">extend</span>.<span class="property">helper</span>.<span class="title function_">get</span>(<span class="string">&#x27;css&#x27;</span>).<span class="title function_">bind</span>(hexo);</span><br><span class="line"><span class="keyword">const</span> js = hexo.<span class="property">extend</span>.<span class="property">helper</span>.<span class="title function_">get</span>(<span class="string">&#x27;js&#x27;</span>).<span class="title function_">bind</span>(hexo);</span><br><span class="line"></span><br><span class="line">hexo.<span class="property">extend</span>.<span class="property">injector</span>.<span class="title function_">register</span>(<span class="string">&#x27;head_end&#x27;</span>, <span class="function">() =&gt;</span> &#123;</span><br><span class="line">  <span class="keyword">return</span> <span class="title function_">css</span>(<span class="string">&#x27;https://cdn.jsdelivr.net/npm/aplayer@1.10.1/dist/APlayer.min.css&#x27;</span>);</span><br><span class="line">&#125;, <span class="string">&#x27;music&#x27;</span>);</span><br><span class="line"></span><br><span class="line">hexo.<span class="property">extend</span>.<span class="property">injector</span>.<span class="title function_">register</span>(<span class="string">&#x27;body_end&#x27;</span>, <span class="string">&#x27;&lt;script src=&quot;https://cdn.jsdelivr.net/npm/aplayer@1.10.1/dist/APlayer.min.js&quot;&gt;&#x27;</span>, <span class="string">&#x27;music&#x27;</span>);</span><br><span class="line"></span><br><span class="line">hexo.<span class="property">extend</span>.<span class="property">injector</span>.<span class="title function_">register</span>(<span class="string">&#x27;body_end&#x27;</span>, <span class="function">() =&gt;</span> &#123;</span><br><span class="line">  <span class="keyword">return</span> <span class="title function_">js</span>(<span class="string">&#x27;/js/jquery.js&#x27;</span>);</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<h3 id="3-3-辅助函数（Helper）"><a href="#3-3-辅助函数（Helper）" class="headerlink" title="3.3 辅助函数（Helper）"></a><font size=3>3.3 辅助函数（<code>Helper</code>）</font></h3><h4 id="3-3-1-函数原型"><a href="#3-3-1-函数原型" class="headerlink" title="3.3.1 函数原型"></a><font size=3>3.3.1 函数原型</font></h4><p>辅助函数帮助我们在模板中快速插入内容，我们可以把复杂的代码放在辅助函数而非模板中。</p>
<details class="note info no-icon"><summary><p>点击查看函数原型</p>
</summary>
<figure class="highlight javascript"><figcaption><span>JavaScript [blogRoot]/node_modules/hexo/lib/extend/helper.js</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">class</span> <span class="title class_">Helper</span> &#123;</span><br><span class="line">  <span class="title function_">constructor</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="variable language_">this</span>.<span class="property">store</span> = &#123;&#125;;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * Register a helper plugin</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param</span> &#123;<span class="type">String</span>&#125; <span class="variable">name</span> - The name of the helper plugin</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param</span> &#123;<span class="type">Function</span>&#125; <span class="variable">fn</span> - The helper plugin function</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="title function_">register</span>(<span class="params">name, fn</span>) &#123;</span><br><span class="line">    <span class="keyword">if</span> (!name) <span class="keyword">throw</span> <span class="keyword">new</span> <span class="title class_">TypeError</span>(<span class="string">&#x27;name is required&#x27;</span>);</span><br><span class="line">    <span class="keyword">if</span> (<span class="keyword">typeof</span> fn !== <span class="string">&#x27;function&#x27;</span>) <span class="keyword">throw</span> <span class="keyword">new</span> <span class="title class_">TypeError</span>(<span class="string">&#x27;fn must be a function&#x27;</span>);</span><br><span class="line"></span><br><span class="line">    <span class="variable language_">this</span>.<span class="property">store</span>[name] = fn;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</details>

<h4 id="3-3-2-函数使用及说明"><a href="#3-3-2-函数使用及说明" class="headerlink" title="3.3.2 函数使用及说明"></a><font size=3>3.3.2 函数使用及说明</font></h4><figure class="highlight javascript"><figcaption><span>JavaScript</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">hexo.<span class="property">extend</span>.<span class="property">helper</span>.<span class="title function_">register</span>(name, <span class="keyword">function</span>(<span class="params"></span>)&#123;</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<p>示例如下，此示例的作用是将<code>js</code>封装成一个函数，只需要自己填写要调用的脚本文件名称，就可以调用特定路径下的相应文件。</p>
<figure class="highlight javascript"><figcaption><span>JavaScript</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">hexo.<span class="property">extend</span>.<span class="property">helper</span>.<span class="title function_">register</span>(<span class="string">&#x27;js&#x27;</span>, <span class="keyword">function</span>(<span class="params">path</span>)&#123;</span><br><span class="line">  <span class="keyword">return</span> <span class="string">&#x27;&lt;script src=&quot;&#x27;</span> + path + <span class="string">&#x27;&quot;&gt;&lt;/script&gt;&#x27;</span>;</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<p>函数注册通过辅助函数注册后，可以通过以下格式调用。</p>
<figure class="highlight plaintext"><figcaption><span>nunjuck</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">//在nunjuck模板中使用格式</span><br><span class="line">&#123;&#123;- js(&#x27;script.js&#x27;) &#125;&#125;</span><br><span class="line"></span><br><span class="line">//渲染之后为以下语句</span><br><span class="line">&lt;script src=&quot;script.js&quot;&gt;&lt;/script&gt;</span><br></pre></td></tr></table></figure>
<h1 id="二、尝试Hexo中最基本的插件"><a href="#二、尝试Hexo中最基本的插件" class="headerlink" title="二、尝试Hexo中最基本的插件"></a><font size=3>二、尝试<code>Hexo</code>中最基本的插件</font></h1><p>首先呢需要初始化一个新的站点目录，不做任何修改，以便于测试自己的写的基本插件是否生效。然后就可以开始编写插件啦😄。</p>
<figure class="highlight shell"><figcaption><span>shell</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">初始化一个新文件夹作为站点</span></span><br><span class="line">hexo init npm-test</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">进入该站点文件夹，</span></span><br><span class="line">cd npm-test</span><br></pre></td></tr></table></figure>

<h2 id="1-脚本（Scripts）测试"><a href="#1-脚本（Scripts）测试" class="headerlink" title="1. 脚本（Scripts）测试"></a><font size=3>1. 脚本（<code>Scripts</code>）测试</font></h2><h3 id="1-1-过滤器（Filter）测试"><a href="#1-1-过滤器（Filter）测试" class="headerlink" title="1.1 过滤器（Filter）测试"></a><font size=3>1.1 过滤器（<code>Filter</code>）测试</font></h3><p>在站点根目录下新建<code>scripts</code>文件夹，并新建一个<code>test.js</code>文件，添加以下内容，在编写环境控制台输出一段提示字符。</p>
<figure class="highlight javascript"><figcaption><span>JavaScript</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//before_exit表示在 Hexo 即将结束时执行，也就是在 hexo.exit 被调用后执行</span></span><br><span class="line">hexo.<span class="property">extend</span>.<span class="property">filter</span>.<span class="title function_">register</span>(<span class="string">&#x27;before_exit&#x27;</span>, <span class="keyword">function</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">`测试程序加载成功(ฅ&gt;ω&lt;*ฅ)`</span>)</span><br><span class="line">&#125;, priority);</span><br></pre></td></tr></table></figure>

<h3 id="1-2-注入器（Injector）测试"><a href="#1-2-注入器（Injector）测试" class="headerlink" title="1.2 注入器（Injector）测试"></a><font size=3>1.2 注入器（<code>Injector</code>）测试</font></h3><p>在<code>scripts/test.js</code>文件中添加以下内容，由于要实现的效果程序较长，还请点击折叠部分查看。该测试程序实现的效果是在所有页面加载一个点击产生礼花炸开效果的脚本，并且在渲染后页面的控制台输出一段提示字符。该段程序可以也可以放在过滤器中。</p>
<details class="note info no-icon"><summary><p>点击查看完整测试程序</p>
</summary>
<figure class="highlight javascript"><figcaption><span>JavaScript</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> user_info_js = <span class="string">`</span></span><br><span class="line"><span class="string">&lt;script&gt;</span></span><br><span class="line"><span class="string">  class Circle &#123;</span></span><br><span class="line"><span class="string">    constructor(&#123; origin, speed, color, angle, context &#125;) &#123;</span></span><br><span class="line"><span class="string">      this.origin = origin</span></span><br><span class="line"><span class="string">      this.position = &#123; ...this.origin &#125;</span></span><br><span class="line"><span class="string">      this.color = color</span></span><br><span class="line"><span class="string">      this.speed = speed</span></span><br><span class="line"><span class="string">      this.angle = angle</span></span><br><span class="line"><span class="string">      this.context = context</span></span><br><span class="line"><span class="string">      this.renderCount = 0</span></span><br><span class="line"><span class="string">    &#125;</span></span><br><span class="line"><span class="string">  </span></span><br><span class="line"><span class="string">    draw() &#123;</span></span><br><span class="line"><span class="string">      this.context.fillStyle = this.color</span></span><br><span class="line"><span class="string">      this.context.beginPath()</span></span><br><span class="line"><span class="string">      this.context.arc(this.position.x, this.position.y, 2, 0, Math.PI * 2)</span></span><br><span class="line"><span class="string">      this.context.fill()</span></span><br><span class="line"><span class="string">    &#125;</span></span><br><span class="line"><span class="string">  </span></span><br><span class="line"><span class="string">    move() &#123;</span></span><br><span class="line"><span class="string">      this.position.x = (Math.sin(this.angle) * this.speed) + this.position.x</span></span><br><span class="line"><span class="string">      this.position.y = (Math.cos(this.angle) * this.speed) + this.position.y + (this.renderCount * 0.3)</span></span><br><span class="line"><span class="string">      this.renderCount++</span></span><br><span class="line"><span class="string">    &#125;</span></span><br><span class="line"><span class="string">  &#125;</span></span><br><span class="line"><span class="string">  </span></span><br><span class="line"><span class="string">  class Boom &#123;</span></span><br><span class="line"><span class="string">    constructor (&#123; origin, context, circleCount = 16, area &#125;) &#123;</span></span><br><span class="line"><span class="string">      this.origin = origin</span></span><br><span class="line"><span class="string">      this.context = context</span></span><br><span class="line"><span class="string">      this.circleCount = circleCount</span></span><br><span class="line"><span class="string">      this.area = area</span></span><br><span class="line"><span class="string">      this.stop = false</span></span><br><span class="line"><span class="string">      this.circles = []</span></span><br><span class="line"><span class="string">    &#125;</span></span><br><span class="line"><span class="string">  </span></span><br><span class="line"><span class="string">    randomArray(range) &#123;</span></span><br><span class="line"><span class="string">      const length = range.length</span></span><br><span class="line"><span class="string">      const randomIndex = Math.floor(length * Math.random())</span></span><br><span class="line"><span class="string">      return range[randomIndex]</span></span><br><span class="line"><span class="string">    &#125;</span></span><br><span class="line"><span class="string">  </span></span><br><span class="line"><span class="string">    randomColor() &#123;</span></span><br><span class="line"><span class="string">      const range = [&#x27;8&#x27;, &#x27;9&#x27;, &#x27;A&#x27;, &#x27;B&#x27;, &#x27;C&#x27;, &#x27;D&#x27;, &#x27;E&#x27;, &#x27;F&#x27;]</span></span><br><span class="line"><span class="string">      return &#x27;#&#x27; + this.randomArray(range) + this.randomArray(range) + this.randomArray(range) + this.randomArray(range) + this.randomArray(range) + this.randomArray(range)</span></span><br><span class="line"><span class="string">    &#125;</span></span><br><span class="line"><span class="string">  </span></span><br><span class="line"><span class="string">    randomRange(start, end) &#123;</span></span><br><span class="line"><span class="string">      return (end - start) * Math.random() + start</span></span><br><span class="line"><span class="string">    &#125;</span></span><br><span class="line"><span class="string">  </span></span><br><span class="line"><span class="string">    init() &#123;</span></span><br><span class="line"><span class="string">      for(let i = 0; i &lt; this.circleCount; i++) &#123;</span></span><br><span class="line"><span class="string">        const circle = new Circle(&#123;</span></span><br><span class="line"><span class="string">          context: this.context,</span></span><br><span class="line"><span class="string">          origin: this.origin,</span></span><br><span class="line"><span class="string">          color: this.randomColor(),</span></span><br><span class="line"><span class="string">          angle: this.randomRange(Math.PI - 1, Math.PI + 1),</span></span><br><span class="line"><span class="string">          speed: this.randomRange(1, 6)</span></span><br><span class="line"><span class="string">        &#125;)</span></span><br><span class="line"><span class="string">        this.circles.push(circle)</span></span><br><span class="line"><span class="string">      &#125;</span></span><br><span class="line"><span class="string">    &#125;</span></span><br><span class="line"><span class="string">  </span></span><br><span class="line"><span class="string">    move() &#123;</span></span><br><span class="line"><span class="string">      this.circles.forEach((circle, index) =&gt; &#123;</span></span><br><span class="line"><span class="string">        if (circle.position.x &gt; this.area.width || circle.position.y &gt; this.area.height) &#123;</span></span><br><span class="line"><span class="string">          return this.circles.splice(index, 1)</span></span><br><span class="line"><span class="string">        &#125;</span></span><br><span class="line"><span class="string">        circle.move()</span></span><br><span class="line"><span class="string">      &#125;)</span></span><br><span class="line"><span class="string">      if (this.circles.length == 0) &#123;</span></span><br><span class="line"><span class="string">        this.stop = true</span></span><br><span class="line"><span class="string">      &#125;</span></span><br><span class="line"><span class="string">    &#125;</span></span><br><span class="line"><span class="string">  </span></span><br><span class="line"><span class="string">    draw() &#123;</span></span><br><span class="line"><span class="string">      this.circles.forEach(circle =&gt; circle.draw())</span></span><br><span class="line"><span class="string">    &#125;</span></span><br><span class="line"><span class="string">  &#125;</span></span><br><span class="line"><span class="string">  </span></span><br><span class="line"><span class="string">  class CursorSpecialEffects &#123;</span></span><br><span class="line"><span class="string">    constructor() &#123;</span></span><br><span class="line"><span class="string">      this.computerCanvas = document.createElement(&#x27;canvas&#x27;)</span></span><br><span class="line"><span class="string">      this.renderCanvas = document.createElement(&#x27;canvas&#x27;)</span></span><br><span class="line"><span class="string">  </span></span><br><span class="line"><span class="string">      this.computerContext = this.computerCanvas.getContext(&#x27;2d&#x27;)</span></span><br><span class="line"><span class="string">      this.renderContext = this.renderCanvas.getContext(&#x27;2d&#x27;)</span></span><br><span class="line"><span class="string">  </span></span><br><span class="line"><span class="string">      this.globalWidth = window.innerWidth</span></span><br><span class="line"><span class="string">      this.globalHeight = window.innerHeight</span></span><br><span class="line"><span class="string">  </span></span><br><span class="line"><span class="string">      this.booms = []</span></span><br><span class="line"><span class="string">      this.running = false</span></span><br><span class="line"><span class="string">    &#125;</span></span><br><span class="line"><span class="string">  </span></span><br><span class="line"><span class="string">    handleMouseDown(e) &#123;</span></span><br><span class="line"><span class="string">      const boom = new Boom(&#123;</span></span><br><span class="line"><span class="string">        origin: &#123; x: e.clientX, y: e.clientY &#125;,</span></span><br><span class="line"><span class="string">        context: this.computerContext,</span></span><br><span class="line"><span class="string">        area: &#123;</span></span><br><span class="line"><span class="string">          width: this.globalWidth,</span></span><br><span class="line"><span class="string">          height: this.globalHeight</span></span><br><span class="line"><span class="string">        &#125;</span></span><br><span class="line"><span class="string">      &#125;)</span></span><br><span class="line"><span class="string">      boom.init()</span></span><br><span class="line"><span class="string">      this.booms.push(boom)</span></span><br><span class="line"><span class="string">      this.running || this.run()</span></span><br><span class="line"><span class="string">    &#125;</span></span><br><span class="line"><span class="string">  </span></span><br><span class="line"><span class="string">    handlePageHide() &#123;</span></span><br><span class="line"><span class="string">      this.booms = []</span></span><br><span class="line"><span class="string">      this.running = false</span></span><br><span class="line"><span class="string">    &#125;</span></span><br><span class="line"><span class="string">  </span></span><br><span class="line"><span class="string">    init() &#123;</span></span><br><span class="line"><span class="string">      const style = this.renderCanvas.style</span></span><br><span class="line"><span class="string">      style.position = &#x27;fixed&#x27;</span></span><br><span class="line"><span class="string">      style.top = style.left = 0</span></span><br><span class="line"><span class="string">      style.zIndex = &#x27;999999999999999999999999999999999999999999&#x27;</span></span><br><span class="line"><span class="string">      style.pointerEvents = &#x27;none&#x27;</span></span><br><span class="line"><span class="string">  </span></span><br><span class="line"><span class="string">      style.width = this.renderCanvas.width = this.computerCanvas.width = this.globalWidth</span></span><br><span class="line"><span class="string">      style.height = this.renderCanvas.height = this.computerCanvas.height = this.globalHeight</span></span><br><span class="line"><span class="string">  </span></span><br><span class="line"><span class="string">      document.body.append(this.renderCanvas)</span></span><br><span class="line"><span class="string">  </span></span><br><span class="line"><span class="string">      window.addEventListener(&#x27;mousedown&#x27;, this.handleMouseDown.bind(this))</span></span><br><span class="line"><span class="string">      window.addEventListener(&#x27;pagehide&#x27;, this.handlePageHide.bind(this))</span></span><br><span class="line"><span class="string">    &#125;</span></span><br><span class="line"><span class="string">  </span></span><br><span class="line"><span class="string">    run() &#123;</span></span><br><span class="line"><span class="string">      this.running = true</span></span><br><span class="line"><span class="string">      if (this.booms.length == 0) &#123;</span></span><br><span class="line"><span class="string">        return this.running = false</span></span><br><span class="line"><span class="string">      &#125;</span></span><br><span class="line"><span class="string">  </span></span><br><span class="line"><span class="string">      requestAnimationFrame(this.run.bind(this))</span></span><br><span class="line"><span class="string">  </span></span><br><span class="line"><span class="string">      this.computerContext.clearRect(0, 0, this.globalWidth, this.globalHeight)</span></span><br><span class="line"><span class="string">      this.renderContext.clearRect(0, 0, this.globalWidth, this.globalHeight)</span></span><br><span class="line"><span class="string">  </span></span><br><span class="line"><span class="string">      this.booms.forEach((boom, index) =&gt; &#123;</span></span><br><span class="line"><span class="string">        if (boom.stop) &#123;</span></span><br><span class="line"><span class="string">          return this.booms.splice(index, 1)</span></span><br><span class="line"><span class="string">        &#125;</span></span><br><span class="line"><span class="string">        boom.move()</span></span><br><span class="line"><span class="string">        boom.draw()</span></span><br><span class="line"><span class="string">      &#125;)</span></span><br><span class="line"><span class="string">      this.renderContext.drawImage(this.computerCanvas, 0, 0, this.globalWidth, this.globalHeight)</span></span><br><span class="line"><span class="string">    &#125;</span></span><br><span class="line"><span class="string">  &#125;</span></span><br><span class="line"><span class="string">  </span></span><br><span class="line"><span class="string">  const cursorSpecialEffects = new CursorSpecialEffects()</span></span><br><span class="line"><span class="string">  cursorSpecialEffects.init()</span></span><br><span class="line"><span class="string">  console.log(&#x27;点击效果程序加载成功(ฅ&gt;ω&lt;*ฅ)&#x27;)</span></span><br><span class="line"><span class="string">&lt;/script&gt;</span></span><br><span class="line"><span class="string">`</span></span><br><span class="line">hexo.<span class="property">extend</span>.<span class="property">injector</span>.<span class="title function_">register</span>(<span class="string">&#x27;body_end&#x27;</span>, user_info_js, <span class="string">&quot;default&quot;</span>)</span><br></pre></td></tr></table></figure>
</details>

<h2 id="2-插件（Packages）测试"><a href="#2-插件（Packages）测试" class="headerlink" title="2. 插件（Packages）测试"></a><font size=3>2. 插件（<code>Packages</code>）测试</font></h2><p>上边介绍了脚本（<code>Scripts</code>）的测试程序，准备写插件的测试程序的时候发现，插件的测试程序其实和上边的测试程序是一模一样的，只不过是一个直接建立脚本文件，一个是另外生成一个插件，那这里就梳理一下从编写测试插件到安装插件然后运运行的过程吧。</p>
<h3 id="2-1-创建插件文件夹并进行初始化"><a href="#2-1-创建插件文件夹并进行初始化" class="headerlink" title="2.1 创建插件文件夹并进行初始化"></a><font size=3>2.1 创建插件文件夹并进行初始化</font></h3><figure class="highlight shell"><figcaption><span>shell</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">新建文件夹</span></span><br><span class="line">mkdir hexo-plugins-test</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">进入插件文件夹并初始化</span></span><br><span class="line">cd hexo-plugins-test/ &amp;&amp; npm init</span><br></pre></td></tr></table></figure>
<p>创建并初始化相应文件夹后，会生成<code>package.json</code>文件，文件内容如下，基本都是默认的，这个<code>main</code>要注意，这里的<code>index.js</code>为<code>Hexo</code>使用该插件的时候入口脚本，所以插件中的主程序要写在该文件中。</p>
<figure class="highlight json"><figcaption><span>json</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line">  <span class="attr">&quot;name&quot;</span><span class="punctuation">:</span> <span class="string">&quot;hexo-plugins-test&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;version&quot;</span><span class="punctuation">:</span> <span class="string">&quot;0.0.0&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;description&quot;</span><span class="punctuation">:</span> <span class="string">&quot;我的插件测试程序&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;main&quot;</span><span class="punctuation">:</span> <span class="string">&quot;index.js&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;scripts&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">    <span class="attr">&quot;test&quot;</span><span class="punctuation">:</span> <span class="string">&quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;</span></span><br><span class="line">  <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;author&quot;</span><span class="punctuation">:</span> <span class="string">&quot;qidaink&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;license&quot;</span><span class="punctuation">:</span> <span class="string">&quot;ISC&quot;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="2-2-创建index-js主程序文件并添加测试程序"><a href="#2-2-创建index-js主程序文件并添加测试程序" class="headerlink" title="2.2 创建index.js主程序文件并添加测试程序"></a><font size=3>2.2 创建<code>index.js</code>主程序文件并添加测试程序</font></h3><p>由于是使用的<code>Vscode</code>软件作为编程环境，所以直接创建该文件，并添加以下程序。此测试程序是将鼠标点击效果脚本添加到了过滤器中，在生成器解析后执行该脚本文件，出现的效果应该为在生成器解析后在编程环境的控制台输出一段测试程序加载成功的提示，随后通过启动本地预览，在那个页面点击都会有礼花炸开的效果，并且页面的控制台也会输出一个效果加载成功的提示。</p>
<details class="note info no-icon"><summary><p>点击查看完整测试程序</p>
</summary>
<figure class="highlight javascript"><figcaption><span>JavaScript</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br></pre></td><td class="code"><pre><span class="line">hexo.<span class="property">extend</span>.<span class="property">filter</span>.<span class="title function_">register</span>(<span class="string">&#x27;after_generate&#x27;</span>, <span class="keyword">function</span>(<span class="params"></span>) &#123;</span><br><span class="line">  <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">`测试程序加载成功(ฅ&gt;ω&lt;*ฅ)`</span>)</span><br><span class="line">  <span class="keyword">var</span> user_info_js = <span class="string">`</span></span><br><span class="line"><span class="string">  &lt;script&gt;</span></span><br><span class="line"><span class="string">    class Circle &#123;</span></span><br><span class="line"><span class="string">      constructor(&#123; origin, speed, color, angle, context &#125;) &#123;</span></span><br><span class="line"><span class="string">        this.origin = origin</span></span><br><span class="line"><span class="string">        this.position = &#123; ...this.origin &#125;</span></span><br><span class="line"><span class="string">        this.color = color</span></span><br><span class="line"><span class="string">        this.speed = speed</span></span><br><span class="line"><span class="string">        this.angle = angle</span></span><br><span class="line"><span class="string">        this.context = context</span></span><br><span class="line"><span class="string">        this.renderCount = 0</span></span><br><span class="line"><span class="string">      &#125;</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">      draw() &#123;</span></span><br><span class="line"><span class="string">        this.context.fillStyle = this.color</span></span><br><span class="line"><span class="string">        this.context.beginPath()</span></span><br><span class="line"><span class="string">        this.context.arc(this.position.x, this.position.y, 2, 0, Math.PI * 2)</span></span><br><span class="line"><span class="string">        this.context.fill()</span></span><br><span class="line"><span class="string">      &#125;</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">      move() &#123;</span></span><br><span class="line"><span class="string">        this.position.x = (Math.sin(this.angle) * this.speed) + this.position.x</span></span><br><span class="line"><span class="string">        this.position.y = (Math.cos(this.angle) * this.speed) + this.position.y + (this.renderCount * 0.3)</span></span><br><span class="line"><span class="string">        this.renderCount++</span></span><br><span class="line"><span class="string">      &#125;</span></span><br><span class="line"><span class="string">    &#125;</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">    class Boom &#123;</span></span><br><span class="line"><span class="string">      constructor (&#123; origin, context, circleCount = 16, area &#125;) &#123;</span></span><br><span class="line"><span class="string">        this.origin = origin</span></span><br><span class="line"><span class="string">        this.context = context</span></span><br><span class="line"><span class="string">        this.circleCount = circleCount</span></span><br><span class="line"><span class="string">        this.area = area</span></span><br><span class="line"><span class="string">        this.stop = false</span></span><br><span class="line"><span class="string">        this.circles = []</span></span><br><span class="line"><span class="string">      &#125;</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">      randomArray(range) &#123;</span></span><br><span class="line"><span class="string">        const length = range.length</span></span><br><span class="line"><span class="string">        const randomIndex = Math.floor(length * Math.random())</span></span><br><span class="line"><span class="string">        return range[randomIndex]</span></span><br><span class="line"><span class="string">      &#125;</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">      randomColor() &#123;</span></span><br><span class="line"><span class="string">        const range = [&#x27;8&#x27;, &#x27;9&#x27;, &#x27;A&#x27;, &#x27;B&#x27;, &#x27;C&#x27;, &#x27;D&#x27;, &#x27;E&#x27;, &#x27;F&#x27;]</span></span><br><span class="line"><span class="string">        return &#x27;#&#x27; + this.randomArray(range) + this.randomArray(range) + this.randomArray(range) + this.randomArray(range) + this.randomArray(range) + this.randomArray(range)</span></span><br><span class="line"><span class="string">      &#125;</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">      randomRange(start, end) &#123;</span></span><br><span class="line"><span class="string">        return (end - start) * Math.random() + start</span></span><br><span class="line"><span class="string">      &#125;</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">      init() &#123;</span></span><br><span class="line"><span class="string">        for(let i = 0; i &lt; this.circleCount; i++) &#123;</span></span><br><span class="line"><span class="string">          const circle = new Circle(&#123;</span></span><br><span class="line"><span class="string">            context: this.context,</span></span><br><span class="line"><span class="string">            origin: this.origin,</span></span><br><span class="line"><span class="string">            color: this.randomColor(),</span></span><br><span class="line"><span class="string">            angle: this.randomRange(Math.PI - 1, Math.PI + 1),</span></span><br><span class="line"><span class="string">            speed: this.randomRange(1, 6)</span></span><br><span class="line"><span class="string">          &#125;)</span></span><br><span class="line"><span class="string">          this.circles.push(circle)</span></span><br><span class="line"><span class="string">        &#125;</span></span><br><span class="line"><span class="string">      &#125;</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">      move() &#123;</span></span><br><span class="line"><span class="string">        this.circles.forEach((circle, index) =&gt; &#123;</span></span><br><span class="line"><span class="string">          if (circle.position.x &gt; this.area.width || circle.position.y &gt; this.area.height) &#123;</span></span><br><span class="line"><span class="string">            return this.circles.splice(index, 1)</span></span><br><span class="line"><span class="string">          &#125;</span></span><br><span class="line"><span class="string">          circle.move()</span></span><br><span class="line"><span class="string">        &#125;)</span></span><br><span class="line"><span class="string">        if (this.circles.length == 0) &#123;</span></span><br><span class="line"><span class="string">          this.stop = true</span></span><br><span class="line"><span class="string">        &#125;</span></span><br><span class="line"><span class="string">      &#125;</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">      draw() &#123;</span></span><br><span class="line"><span class="string">        this.circles.forEach(circle =&gt; circle.draw())</span></span><br><span class="line"><span class="string">      &#125;</span></span><br><span class="line"><span class="string">    &#125;</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">    class CursorSpecialEffects &#123;</span></span><br><span class="line"><span class="string">      constructor() &#123;</span></span><br><span class="line"><span class="string">        this.computerCanvas = document.createElement(&#x27;canvas&#x27;)</span></span><br><span class="line"><span class="string">        this.renderCanvas = document.createElement(&#x27;canvas&#x27;)</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">        this.computerContext = this.computerCanvas.getContext(&#x27;2d&#x27;)</span></span><br><span class="line"><span class="string">        this.renderContext = this.renderCanvas.getContext(&#x27;2d&#x27;)</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">        this.globalWidth = window.innerWidth</span></span><br><span class="line"><span class="string">        this.globalHeight = window.innerHeight</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">        this.booms = []</span></span><br><span class="line"><span class="string">        this.running = false</span></span><br><span class="line"><span class="string">      &#125;</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">      handleMouseDown(e) &#123;</span></span><br><span class="line"><span class="string">        const boom = new Boom(&#123;</span></span><br><span class="line"><span class="string">          origin: &#123; x: e.clientX, y: e.clientY &#125;,</span></span><br><span class="line"><span class="string">          context: this.computerContext,</span></span><br><span class="line"><span class="string">          area: &#123;</span></span><br><span class="line"><span class="string">            width: this.globalWidth,</span></span><br><span class="line"><span class="string">            height: this.globalHeight</span></span><br><span class="line"><span class="string">          &#125;</span></span><br><span class="line"><span class="string">        &#125;)</span></span><br><span class="line"><span class="string">        boom.init()</span></span><br><span class="line"><span class="string">        this.booms.push(boom)</span></span><br><span class="line"><span class="string">        this.running || this.run()</span></span><br><span class="line"><span class="string">      &#125;</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">      handlePageHide() &#123;</span></span><br><span class="line"><span class="string">        this.booms = []</span></span><br><span class="line"><span class="string">        this.running = false</span></span><br><span class="line"><span class="string">      &#125;</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">      init() &#123;</span></span><br><span class="line"><span class="string">        const style = this.renderCanvas.style</span></span><br><span class="line"><span class="string">        style.position = &#x27;fixed&#x27;</span></span><br><span class="line"><span class="string">        style.top = style.left = 0</span></span><br><span class="line"><span class="string">        style.zIndex = &#x27;999999999999999999999999999999999999999999&#x27;</span></span><br><span class="line"><span class="string">        style.pointerEvents = &#x27;none&#x27;</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">        style.width = this.renderCanvas.width = this.computerCanvas.width = this.globalWidth</span></span><br><span class="line"><span class="string">        style.height = this.renderCanvas.height = this.computerCanvas.height = this.globalHeight</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">        document.body.append(this.renderCanvas)</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">        window.addEventListener(&#x27;mousedown&#x27;, this.handleMouseDown.bind(this))</span></span><br><span class="line"><span class="string">        window.addEventListener(&#x27;pagehide&#x27;, this.handlePageHide.bind(this))</span></span><br><span class="line"><span class="string">      &#125;</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">      run() &#123;</span></span><br><span class="line"><span class="string">        this.running = true</span></span><br><span class="line"><span class="string">        if (this.booms.length == 0) &#123;</span></span><br><span class="line"><span class="string">          return this.running = false</span></span><br><span class="line"><span class="string">        &#125;</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">        requestAnimationFrame(this.run.bind(this))</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">        this.computerContext.clearRect(0, 0, this.globalWidth, this.globalHeight)</span></span><br><span class="line"><span class="string">        this.renderContext.clearRect(0, 0, this.globalWidth, this.globalHeight)</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">        this.booms.forEach((boom, index) =&gt; &#123;</span></span><br><span class="line"><span class="string">          if (boom.stop) &#123;</span></span><br><span class="line"><span class="string">            return this.booms.splice(index, 1)</span></span><br><span class="line"><span class="string">          &#125;</span></span><br><span class="line"><span class="string">          boom.move()</span></span><br><span class="line"><span class="string">          boom.draw()</span></span><br><span class="line"><span class="string">        &#125;)</span></span><br><span class="line"><span class="string">        this.renderContext.drawImage(this.computerCanvas, 0, 0, this.globalWidth, this.globalHeight)</span></span><br><span class="line"><span class="string">      &#125;</span></span><br><span class="line"><span class="string">    &#125;</span></span><br><span class="line"><span class="string">    </span></span><br><span class="line"><span class="string">    const cursorSpecialEffects = new CursorSpecialEffects()</span></span><br><span class="line"><span class="string">    cursorSpecialEffects.init()</span></span><br><span class="line"><span class="string">    console.log(&#x27;点击效果程序加载成功(ฅ&gt;ω&lt;*ฅ)&#x27;)</span></span><br><span class="line"><span class="string">  &lt;/script&gt;</span></span><br><span class="line"><span class="string">  `</span></span><br><span class="line">  hexo.<span class="property">extend</span>.<span class="property">injector</span>.<span class="title function_">register</span>(<span class="string">&#x27;body_end&#x27;</span>, user_info_js, <span class="string">&quot;default&quot;</span>)</span><br><span class="line"></span><br><span class="line">&#125;, <span class="number">98</span>);</span><br></pre></td></tr></table></figure>
</details>

<h3 id="2-3-打包并发布程序到npm"><a href="#2-3-打包并发布程序到npm" class="headerlink" title="2.3 打包并发布程序到npm"></a><font size=3>2.3 打包并发布程序到<code>npm</code></font></h3><p>这个吧，要先看后边的笔记，了解一下如何在npm发布程序，在这里直接执行以下命令。</p>
<figure class="highlight shell"><figcaption><span>shell</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">发布版本到npm</span></span><br><span class="line">npm publish</span><br></pre></td></tr></table></figure>
<p>出现以下提示信息代表发布成功。</p>
<figure class="highlight shell"><figcaption><span>shell</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">npm notice </span><br><span class="line">npm notice package: hexo-plugins-test@0.0.0</span><br><span class="line">npm notice === Tarball Contents ===</span><br><span class="line">npm notice 5.5kB index.js</span><br><span class="line">npm notice 244B  package.json</span><br><span class="line">npm notice === Tarball Details ===</span><br><span class="line">npm notice name:          hexo-plugins-test</span><br><span class="line">npm notice version:       0.0.0</span><br><span class="line">npm notice package size:  1.8 kB</span><br><span class="line">npm notice unpacked size: 5.8 kB</span><br><span class="line">npm notice shasum:        50ce71a91babf482f12b0f54a05a7ad48c3d8298</span><br><span class="line">npm notice integrity:     sha512-EZwg7y6/fCmv/[...]oUQJ/Y0pKTR9g==</span><br><span class="line">npm notice total files:   2</span><br><span class="line">npm notice</span><br><span class="line">+ hexo-plugins-test@0.0.0</span><br></pre></td></tr></table></figure>

<h3 id="2-4-进入测试站点并安装插件"><a href="#2-4-进入测试站点并安装插件" class="headerlink" title="2.4 进入测试站点并安装插件"></a><font size=3>2.4 进入测试站点并安装插件</font></h3><figure class="highlight shell"><figcaption><span>shell</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">进入自己的站点根目录（blogRoot代表站点根目录）</span></span><br><span class="line">cd [blogRoot]/</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">安装插件</span></span><br><span class="line">npm install hexo-plugins-test</span><br></pre></td></tr></table></figure>

<p>若无报错，即可进行下一步，启动本地预览，查看效果。</p>
<h3 id="2-5-启动本地预览"><a href="#2-5-启动本地预览" class="headerlink" title="2.5 启动本地预览"></a><font size=3>2.5 启动本地预览</font></h3><figure class="highlight shell"><figcaption><span>shell</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo cl &amp;&amp; hexo g &amp;&amp; hexo s</span><br></pre></td></tr></table></figure>
    </div>

    
    
    

    <footer class="post-footer">




    <div>
        
            <div style="text-align:center;color: #ccc;font-size:14px;">
            ----------本文结束
            <i class="fas fa-fan fa-spin" style="color: #FF1493; font-size: 1rem"></i>
            感谢您的阅读----------
            </div>
        
    </div>





  
  <div class="my_post_copyright"> 
    <p><span>文章标题:</span><a href="/post/72cb261c.html">LV01-Hexo-03-Hexo的两种插件</a></p>
    <p><span>文章作者:</span><a href="/" title="欢迎访问 《苏木》 的学习笔记">苏木</a></p>
    <p><span>发布时间:</span>2023年07月02日 - 16:16</p>
    <p><span>最后更新:</span>2025年06月14日 - 00:25</p>
    <p><span>原始链接:</span><a href="/post/72cb261c.html" title="LV01-Hexo-03-Hexo的两种插件">https://sumumm.github.io/post/72cb261c.html</a></p>
    <p><span>许可协议:</span><i class="fab fa-creative-commons"></i> <a rel="license" href= "https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
  </div>
  


          <div class="post-tags">
              <a href="/tags/%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/" rel="tag"><i class="fa fa-tag"></i> 博客搭建</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/post/d1be343.html" rel="prev" title="LV02-NexT-01-简介与安装">
                  <i class="fa fa-angle-left"></i> LV02-NexT-01-简介与安装
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/post/5d78b485.html" rel="next" title="LV01-Hexo-02-npm包的发布与管理">
                  LV01-Hexo-02-npm包的发布与管理 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2017 – 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">苏木</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">3.7m</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">225:26</span>
  </span>
</div>




    <span id="sitetime"></span>
    <script defer language=javascript>
        function siteTime()
        {
            window.setTimeout("siteTime()", 1000);
            var seconds = 1000;
            var minutes = seconds * 60;
            var hours = minutes * 60;
            var days = hours * 24;
            var years = days * 365;
            var today = new Date();
            var todayYear = today.getFullYear();
            var todayMonth = today.getMonth()+1;
            var todayDate = today.getDate();
            var todayHour = today.getHours();
            var todayMinute = today.getMinutes();
            var todaySecond = today.getSeconds();
            /*==================================================
            Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
            year        - 作为date对象的年份，为4位年份值
            month       - 0-11之间的整数，做为date对象的月份
            day         - 1-31之间的整数，做为date对象的天数
            hours       - 0(午夜24点)-23之间的整数，做为date对象的小时数
            minutes     - 0-59之间的整数，做为date对象的分钟数
            seconds     - 0-59之间的整数，做为date对象的秒数
            microseconds - 0-999之间的整数，做为date对象的毫秒数
            ==================================================*/
            var t1 = Date.UTC(2017, 
                              5, 
                              19, 
                              0, 
                              0, 
                              0); //北京时间
            var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond);
            var diff = t2-t1;
            var diffYears = Math.floor(diff/years);
            var diffDays = Math.floor((diff/days)-diffYears*365);
            var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours);
            var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes);
            var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds);
            document.getElementById("sitetime").innerHTML="已在这里 "+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒";
        }
        siteTime();
    </script>



    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.umd.js" integrity="sha256-ytMJGN3toR+a84u7g7NuHm91VIR06Q41kMWDr2pq7Zo=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>

  <script src="/js/third-party/pace.js"></script>


  




  

  <script class="next-config" data-name="enableMath" type="application/json">false</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


 
        <div id="click-show-text"
            data-mobile = false
            data-text = 富强,民主,文明,和谐,自由,平等,公正,法制,爱国,敬业,诚信,友善
            data-fontsize = 15px
            data-random= false>
        </div>
       

      
        <script async src=https://cdn.jsdelivr.net/npm/hexo-next-mouse-effect@latest/click/showText.js></script>
      

      
    




    <script async src="/js/fancybox_param.js"></script>





<!-- APlayer本体 -->



</body>
</html>
